home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / dspack / DSPACK231.exe / {app} / Demos / D5 / DVDPlay / Unit1.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2002-11-24  |  10.7 KB  |  358 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, DSPack,
  7.   Menus, ExtCtrls, ComCtrls, StdCtrls, DirectShow9, OleServer, DSUtil,
  8.   ImgList, ToolWin, shellapi;
  9.  
  10. type
  11.   TFormDVDPlayer = class(TForm)
  12.     MainMenu: TMainMenu;
  13.     FileMenu: TMenuItem;
  14.     OpenMenu: TMenuItem;
  15.     ExitMenu: TMenuItem;
  16.     OpenDialog: TOpenDialog;
  17.     ControlMenu: TMenuItem;
  18.     PlayMenu: TMenuItem;
  19.     PauseMenu: TMenuItem;
  20.     StopMenu: TMenuItem;
  21.     ToolBar: TToolBar;
  22.     btPreviousChapter: TToolButton;
  23.     btRewind: TToolButton;
  24.     btPause: TToolButton;
  25.     btPlay: TToolButton;
  26.     btStop: TToolButton;
  27.     btFastForward: TToolButton;
  28.     btNextChapter: TToolButton;
  29.     ToolButton8: TToolButton;
  30.     btRootMenu: TToolButton;
  31.     btFullScreen: TToolButton;
  32.     btFrameStep: TToolButton;
  33.     ImageList: TImageList;
  34.     StepForwardMenu: TMenuItem;
  35.     OptionsMenu: TMenuItem;
  36.     FullscreenMenu: TMenuItem;
  37.     Popup: TPopupMenu;
  38.     N1: TMenuItem;
  39.     GoToMenu: TMenuItem;
  40.     PlaySpeed1: TMenuItem;
  41.     NextChapterMenu: TMenuItem;
  42.     PreviousChapterMenu: TMenuItem;
  43.     FastForward1: TMenuItem;
  44.     Rewind1: TMenuItem;
  45.     N4: TMenuItem;
  46.     MenuRoot: TMenuItem;
  47.     TitleMenu: TMenuItem;
  48.     N5: TMenuItem;
  49.     BookmarksMenu: TMenuItem;
  50.     SavebookmarkMenu: TMenuItem;
  51.     RestorebookmarkMenu: TMenuItem;
  52.     Play2: TMenuItem;
  53.     Pause2: TMenuItem;
  54.     Stop2: TMenuItem;
  55.     N2: TMenuItem;
  56.     GoTo2: TMenuItem;
  57.     NextChapter2: TMenuItem;
  58.     PreviousChapter2: TMenuItem;
  59.     PlaySpeed2: TMenuItem;
  60.     FastForward2: TMenuItem;
  61.     Rewind2: TMenuItem;
  62.     N3: TMenuItem;
  63.     MenuRoot2: TMenuItem;
  64.     TitleMenu2: TMenuItem;
  65.     Fullscreen2: TMenuItem;
  66.     N6: TMenuItem;
  67.     Bookmarks2: TMenuItem;
  68.     Savebookmark2: TMenuItem;
  69.     Restorebookmark2: TMenuItem;
  70.     StatusBar: TStatusBar;
  71.     N7: TMenuItem;
  72.     progdigycom1: TMenuItem;
  73.     VideoWindow: TVideoWindow;
  74.     FilterGraph: TFilterGraph;
  75.     procedure PlayMenuClick(Sender: TObject);
  76.     procedure btStopClick(Sender: TObject);
  77.     procedure btPauseClick(Sender: TObject);
  78.     procedure btFullScreenClick(Sender: TObject);
  79.     procedure btFrameStepClick(Sender: TObject);
  80.     procedure btRootMenuClick(Sender: TObject);
  81.     procedure VideoWindowMouseMove(Sender: TObject; Shift: TShiftState; X,
  82.       Y: Integer);
  83.     procedure VideoWindowMouseUp(Sender: TObject; Button: TMouseButton;
  84.       Shift: TShiftState; X, Y: Integer);
  85.     procedure btNextChapterClick(Sender: TObject);
  86.     procedure btPreviousChapterClick(Sender: TObject);
  87.     procedure btFastForwardClick(Sender: TObject);
  88.     procedure btRewindClick(Sender: TObject);
  89.     procedure TitleMenuClick(Sender: TObject);
  90.     procedure SavebookmarkMenuClick(Sender: TObject);
  91.     procedure RestorebookmarkMenuClick(Sender: TObject);
  92.     procedure ExitMenuClick(Sender: TObject);
  93.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  94.     procedure OpenMenuClick(Sender: TObject);
  95.     procedure FilterGraphDVDTitleChange(sender: TObject; title: Integer);
  96.     procedure FilterGraphDVDChapterStart(sender: TObject;
  97.       chapter: Integer);
  98.     procedure FilterGraphDVDCurrentHMSFTime(sender: TObject;
  99.       HMSFTimeCode: TDVD_HMSF_TIMECODE; TimeCode: TDVD_TimeCode);
  100.   private
  101.     { DΘclarations privΘes }
  102.   public
  103.     { DΘclarations publiques }
  104.     procedure PlayDVD(FileName: WideString);
  105.   end;
  106.  
  107. var
  108.   FormDVDPlayer: TFormDVDPlayer;
  109.  
  110. implementation
  111.  
  112. {$R *.DFM}
  113.  
  114. procedure TFormDVDPlayer.PlayDVD(FileName: WideString);
  115. var
  116.   Status : TAM_DVD_RenderStatus;
  117.   DvdCmd: IDvdCmd;
  118.   HR: HRESULT;
  119.   DVDControl: IDVDControl2;
  120. begin
  121.   // Activate the filter Graph
  122.   if not FilterGraph.Active then
  123.   begin
  124.     FilterGraph.Active := true;
  125.     // Render DVD
  126.     HR := FilterGraph.RenderDvd(Status, FileName);
  127.     if HR <> S_OK then
  128.     begin
  129.       case HR of
  130.         HRESULT(E_INVALIDARG): Application.MessageBox('Invalid Argument.','Error', mb_ok);
  131.         HRESULT(S_FALSE)     : begin
  132.                         if Status.hrVPEStatus <> 0 then Application.MessageBox(PChar(GetErrorString(Status.hrVPEStatus)), 'Error', mb_OK);
  133.                         if Status.bDvdVolInvalid   then Application.MessageBox('The specified DVD volume to be played does not exist.', 'Error', mb_OK);
  134.                         if Status.bDvdVolUnknown   then Application.MessageBox('No DVD volume is specified or isn''t found.', 'Error', mb_OK);
  135.                         if Status.bNoLine21In      then Application.MessageBox('The video decoder doesn''t produce line 21 (closed captioning) data.', 'Error', mb_OK);
  136.                         if Status.bNoLine21Out     then Application.MessageBox('The video decoder can''t be shown as closed captioning on video due to a problem with graph building.', 'Error', mb_OK);
  137.                         if status.iNumStreamsFailed > 0 then Application.MessageBox('Can''t render one or more stream.', 'Error', mb_OK);
  138.                       end;
  139.         HRESULT(VFW_E_DVD_DECNOTENOUGH) : Application.MessageBox('There isn''t enough hardware or software decoders to decode all streams.','Error', mb_OK);
  140.         HRESULT(VFW_E_DVD_RENDERFAIL)   : Application.MessageBox('Some basic error occurred in building the graph.'#13'Possibilities include the DVD Navigator filter or the video or audio renderer not instantiating,'#13'a trivial connection or pin enumeration failing, or none of the streams rendering.','Error', mb_OK);
  141.       end;
  142.       FilterGraph.ClearGraph;
  143.       exit;
  144.     end;
  145.     FilterGraph.Play;
  146.     FilterGraph.QueryInterface(IDVDControl2, DVDControl);
  147.     DVDControl.SetOption(DVD_NotifyParentalLevelChange,false); //not notify us when parental level changes
  148.     DVDControl.SetOption(DVD_HMSF_TimeCodeEvents, true);       // use new HMSF timecode format
  149.   end
  150.   else
  151.   begin
  152.     FilterGraph.Play;
  153.     FilterGraph.QueryInterface(IDVDControl2, DVDControl);
  154.     DVDControl.PlayForwards(1.0,DVD_CMD_FLAG_None, DvdCmd);
  155.   end;
  156.   DVDControl := nil;
  157. end;
  158.  
  159. procedure TFormDVDPlayer.PlayMenuClick(Sender: TObject);
  160. begin
  161.   PlayDVD('');
  162. end;
  163.  
  164. procedure TFormDVDPlayer.btStopClick(Sender: TObject);
  165. begin
  166.   FilterGraph.Stop;
  167. end;
  168.  
  169. procedure TFormDVDPlayer.btPauseClick(Sender: TObject);
  170. begin
  171.   FilterGraph.Pause;
  172. end;
  173.  
  174. procedure TFormDVDPlayer.btFullScreenClick(Sender: TObject);
  175. begin
  176.   VideoWindow.FullScreen := not VideoWindow.FullScreen;
  177.   btFullScreen.Down := VideoWindow.FullScreen;
  178. end;
  179.  
  180. procedure TFormDVDPlayer.btFrameStepClick(Sender: TObject);
  181. var
  182.   FrameStep: IVideoFrameStep;
  183. begin
  184.   if FilterGraph.Active then
  185.   begin
  186.     FilterGraph.QueryInterface(IVideoFrameStep, FrameStep);
  187.     FrameStep.Step(1,nil);
  188.     FrameStep := nil;
  189.   end;
  190. end;
  191.  
  192. procedure TFormDVDPlayer.btRootMenuClick(Sender: TObject);
  193. var
  194.   DvdCmd: IDvdCmd;
  195.   DvdControl: IDvdControl2;
  196. begin
  197.   if FilterGraph.Active then
  198.   begin
  199.     FilterGraph.QueryInterface(IDvdControl2, DvdControl);
  200.     DvdControl.ShowMenu(DVD_MENU_Root, 0, DvdCmd);
  201.     DvdControl := nil;
  202.   end;
  203. end;
  204.  
  205. procedure TFormDVDPlayer.VideoWindowMouseMove(Sender: TObject;
  206.   Shift: TShiftState; X, Y: Integer);
  207. var
  208.   Point : TPoint;
  209.   DvdControl: IDvdControl2;
  210. begin
  211.   if FilterGraph.Active then
  212.   begin
  213.     FilterGraph.QueryInterface(IDvdControl2, DvdControl);
  214.     Point.x := x;
  215.     Point.y := y;
  216.     DvdControl.SelectAtPosition(Point);
  217.     DvdControl := nil;
  218.   end;
  219. end;
  220.  
  221. procedure TFormDVDPlayer.VideoWindowMouseUp(Sender: TObject;
  222.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  223. var
  224.   Point : TPoint;
  225.   DvdControl: IDvdControl2;
  226. begin
  227.   if FilterGraph.Active then
  228.   begin
  229.     FilterGraph.QueryInterface(IDvdControl2, DvdControl);
  230.     Point.x := x;
  231.     Point.y := y;
  232.     DvdControl.ActivateAtPosition(Point);
  233.     DvdControl := nil;
  234.   end;
  235. end;
  236.  
  237. procedure TFormDVDPlayer.btNextChapterClick(Sender: TObject);
  238. var
  239.   DvdCmd: IDvdCmd;
  240.   DvdControl: IDvdControl2;
  241. begin
  242.   if FilterGraph.Active then
  243.   begin
  244.     FilterGraph.QueryInterface(IDvdControl2, DvdControl);
  245.     DvdControl.PlayNextChapter(DVD_CMD_FLAG_None, DvdCmd);
  246.     DvdControl := nil;
  247.   end;
  248. end;
  249.  
  250. procedure TFormDVDPlayer.btPreviousChapterClick(Sender: TObject);
  251. var
  252.   DvdCmd: IDvdCmd;
  253.   DvdControl: IDvdControl2;
  254. begin
  255.   if FilterGraph.Active then
  256.   begin
  257.     FilterGraph.QueryInterface(IDvdControl2, DvdControl);
  258.     DvdControl.PlayPrevChapter(DVD_CMD_FLAG_None, DvdCmd);
  259.     DvdControl := nil;
  260.   end;
  261. end;
  262.  
  263.  
  264. procedure TFormDVDPlayer.btFastForwardClick(Sender: TObject);
  265. var
  266.   DvdCmd: IDvdCmd;
  267.   DvdControl: IDvdControl2;
  268. begin
  269.   if FilterGraph.Active then
  270.   begin
  271.     FilterGraph.QueryInterface(IDvdControl2, DvdControl);
  272.     DvdControl.PlayForwards(8.0,DVD_CMD_FLAG_None, DvdCmd);
  273.     DvdControl := nil;
  274.   end;
  275. end;
  276.  
  277. procedure TFormDVDPlayer.btRewindClick(Sender: TObject);
  278. var
  279.   DvdCmd: IDvdCmd;
  280.   DvdControl: IDvdControl2;
  281. begin
  282.   if FilterGraph.Active then
  283.   begin
  284.     FilterGraph.QueryInterface(IDvdControl2, DvdControl);
  285.     DvdControl.PlayBackwards(8.0,DVD_CMD_FLAG_None, DvdCmd);
  286.     DvdControl := nil;
  287.   end;
  288. end;
  289.  
  290. procedure TFormDVDPlayer.TitleMenuClick(Sender: TObject);
  291. var
  292.   DvdCmd: IDvdCmd;
  293.   DvdControl: IDvdControl2;
  294. begin
  295.   if FilterGraph.Active then
  296.   begin
  297.     FilterGraph.QueryInterface(IDvdControl2, DvdControl);
  298.     DvdControl.ShowMenu(DVD_MENU_Title, DVD_CMD_FLAG_None, DvdCmd);
  299.     DvdControl := nil;
  300.   end;
  301. end;
  302.  
  303. procedure TFormDVDPlayer.SavebookmarkMenuClick(Sender: TObject);
  304. begin
  305.   FilterGraph.DVDSaveBookmark(ExtractFilePath(Application.EXEName)+'bookmark.bmk');
  306. end;
  307.  
  308. procedure TFormDVDPlayer.RestorebookmarkMenuClick(Sender: TObject);
  309. begin
  310.   FilterGraph.DVDRestoreBookmark(ExtractFilePath(Application.EXEName)+'bookmark.bmk');
  311. end;
  312.  
  313. procedure TFormDVDPlayer.ExitMenuClick(Sender: TObject);
  314. begin
  315.   FilterGraph.ClearGraph;
  316.   FilterGraph.Active := false;
  317.   Application.Terminate;
  318. end;
  319.  
  320. procedure TFormDVDPlayer.FormCloseQuery(Sender: TObject;
  321.   var CanClose: Boolean);
  322. begin
  323.   ExitMenuClick(nil)
  324. end;
  325.  
  326. procedure TFormDVDPlayer.OpenMenuClick(Sender: TObject);
  327. begin
  328.   if OpenDialog.Execute then
  329.   begin
  330.     FilterGraph.ClearGraph;
  331.     FilterGraph.Active := false;
  332.     PlayDVD(OpenDialog.FileName);
  333.   end;
  334.   
  335. end;
  336.  
  337. procedure TFormDVDPlayer.FilterGraphDVDTitleChange(sender: TObject;
  338.   title: Integer);
  339. begin
  340.   statusbar.Panels.Items[1].Text := 'Title '+inttostr(title);
  341. end;
  342.  
  343. procedure TFormDVDPlayer.FilterGraphDVDChapterStart(sender: TObject;
  344.   chapter: Integer);
  345. begin
  346.   statusbar.Panels.Items[2].Text := 'Chapter '+ inttostr(chapter);
  347. end;
  348.  
  349. procedure TFormDVDPlayer.FilterGraphDVDCurrentHMSFTime(sender: TObject;
  350.   HMSFTimeCode: TDVD_HMSF_TIMECODE; TimeCode: TDVD_TimeCode);
  351. begin
  352.   with HMSFTimeCode do
  353.     StatusBar.Panels.Items[0].Text :=
  354.       format('%d:%d:%d',[bHours, bMinutes ,bSeconds]);
  355. end;
  356.  
  357. end.
  358.